package com.laizhenghua.share.device.controller;

import com.laizhenghua.share.common.core.domain.R;
import com.laizhenghua.share.common.core.web.controller.BaseController;
import com.laizhenghua.share.common.core.web.page.TableDataInfo;
import com.laizhenghua.share.common.core.web.page.TableSupport;
import com.laizhenghua.share.device.domain.entity.Station;
import com.laizhenghua.share.device.service.IStationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author laizh
 * @Date 2025/7/19 16:35
 **/
@Tag(name = "站点API")
@RestController
@RequestMapping("/station")
public class StationController extends BaseController {
    private final IStationService iStationService;

    @Autowired
    public StationController(IStationService iStationService) {
        this.iStationService = iStationService;
    }

    @PostMapping("/search-page/list")
    @Operation(summary = "分页查询")
    @Parameters({
            @Parameter(name = TableSupport.PAGE_NUM, description = "分页索引", example = "1"),
            @Parameter(name = TableSupport.PAGE_SIZE, description = "分页大小", example = "10")
    })
    @io.swagger.v3.oas.annotations.parameters.RequestBody(content = {@Content(schema = @Schema(implementation = Station.class))})
    public R<TableDataInfo> searchPageList(@RequestBody Station station) {
        startPage();
        List<Station> list = iStationService.searchPageList(station);
        return R.ok(getDataTable(list));
    }
    @Operation(summary = "保存")
    @PostMapping("/save")
    public R<Station> save(@RequestBody Station station) {
        Station s = iStationService.customSave(station);
        return R.ok(s);
    }

    @Operation(summary = "同步站点位置信息到MongoDB")
    @GetMapping("/update/station/location")
    public R<String> updateStationLocation() {
        String res = iStationService.updateStationLocation();
        return R.ok(res);
    }
}
